package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.service.IStrategyInterestService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("strategyInterests")
public class StrategyInterestController {

    @Autowired
    private IStrategyInterestService strategyInterestService;

    @GetMapping("{strategyId}")
    public Object selectByLile(@PathVariable Long strategyId) {
        JSONResult result = new JSONResult();
        //获取到用户登录信息
        User user = UserContext.getCurrentUser();
        try {
            strategyInterestService.toByLile(strategyId, user);
           // System.out.println(1 / 0);
        } catch (Exception e) {
            result.mark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }
    @GetMapping("{strategyId}/interests")
    public Object selectStrategyId(@PathVariable Long strategyId) {
        JSONResult result = new JSONResult();
        //获取到用户登录信息
        User user = UserContext.getCurrentUser();
        try {
            strategyInterestService.selectStrategyId(strategyId, user);
        } catch (Exception e) {
            result.mark(e.getMessage());
            e.printStackTrace();
        }
        return result;
    }
}
